﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebSite
{
    public partial class Default : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LoginControl_Authenticate(object sender, AuthenticateEventArgs e)
        {            
            string userName = User_Login.UserName;
            string password = User_Login.Password;              

            if (!string.IsNullOrEmpty(userName) && (!string.IsNullOrEmpty(password)))
            {
                {                   
                    WebService.SOAPServiceClient webservice = new WebService.SOAPServiceClient();
                    WebService.Users authUser = new WebService.Users();                    
                    authUser = webservice.readUser(userName);

                    try
                    {

                        if ((authUser.UserName.Equals(userName)) && authUser.PassWord.Equals(password))
                        {
                            Session["UserName"] = userName;
                            Session["isUserLoggedIn"] = "true";
                            e.Authenticated = true;                          
                            Response.Redirect("MainPage.aspx");
                        }
                    }
                    catch (Exception)
                    {

                    }
                    
                }
            }
        }
    }
}